package com.x.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * ClassName: WebMvcConfig
 * Package: IntelliJ IDEA

 * Description:
 * Controller层的配置类:controller、springmvc的配置
 *      1、controller
 *      2、全局异常处理类
 *      3、handlerMapping handlerAdapter
 *      4、静态资源处理
 *      5、jsp 视图资源
 *      6、json转化器
 *      7、拦截器
 * Written by HanXu
 * Create 2024.09.15 14:49
 */

@Configuration
@ComponentScan("com.x")//加入controller下的类、全局异常处理类所在的包
@EnableWebMvc //自动配置handlerMapping、handlerAdapter
public class WebMvcJavaConfig implements WebMvcConfigurer {

    //处理静态资源的方法，开启静态资源的查找
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    //视图解析器,配置jsp文件路径
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/WEB-INF/views/", ".jsp");
    }

    //配置拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //registry.addInterceptor(new xxxInterceptor());
    }


    //配置跨域问题
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        WebMvcConfigurer.super.addCorsMappings(registry);
    }
}
